//pop a new window!
function popWindow(url,height,width){
	var WWidth = width;
	var WHeight = height;
	var WLeft = (window.screen.width - WWidth) / 2;
	var WTop = (window.screen.height - WHeight) / 2;
	window.open(url, "", "left=" + WLeft + ",top=" + WTop + ",scrollbars=yes,width=" + WWidth + ",height=" + WHeight + ",resizable=yes");
}
//forbidden right-click of mouse.
/*
function nocontextmenu() 
{
	event.cancelBubble = true
	event.returnValue = false;
	return false;
}
document.oncontextmenu = nocontextmenu;
*/
// Removes leading whitespaces
function ltrim(value) {
	if(value==null){
		return null;
	}
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function rtrim(value) {
	if(value==null){
		return null;
	}
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim(value) {
	if(value==null){
		return null;
	}
	return ltrim(rtrim(value));
}

function $f(obj){
	return document.getElementById(obj);
}

function unlockPage(){
	var fullDiv=document.getElementById("stop_dbclick_layer");
	if(fullDiv!=null){
		document.body.removeChild(fullDiv);
	}
}
 
//stop repeat click
function lockPage(){ // 修正 IE下锁屏无效果的BUG nieyong 2012.10.18
	var scrollTop = document.documentElement.scrollTop;
	var clientHeight = document.documentElement.clientHeight;
	var fullDiv=document.createElement("div");
	fullDiv.id = "stop_dbclick_layer";
	fullDiv.style.height=parseInt(scrollTop)+parseInt(clientHeight)+"px";
	fullDiv.style.width="100%";
	fullDiv.style.position="absolute";
	fullDiv.style.top="0px";
	fullDiv.style.left="0px";
	fullDiv.style.zIndex=19600;
	document.body.appendChild(fullDiv);
	document.getElementById("stop_dbclick_layer").innerHTML=
		"<div style='width:100%;height:100%;position:absolute;top:0; left:0;z-index:19600'></div>"+		
		"<table width='100%' style='height:100%;position:fixed;top:0; left:0;z-index:19601'>" +
			"<tr align='center' width='100%'>" +
			"<td align='center'>" +
				"<img src='../images/system/loading_01.gif' />" +
			"</td>" +
			"</tr>" +
		"</table>";
}

/*
//stop repeat click   锁屏原版备份 nieyong 2012.10.18
function lockPage(){
	var scrollTop = document.documentElement.scrollTop;
	var clientHeight = document.documentElement.clientHeight;
	//alert(scrollTop+"、"+clientHeight+"、"+parseInt(clientHeight)/2);
	//alert(parseInt(scrollTop)+(parseInt(clientHeight)/2));
	var fullDiv=document.createElement("div");
	fullDiv.id = "stop_dbclick_layer";
	//fullDiv.style.position="absolute";
	fullDiv.style.filter="alpha(opacity=100);";
	fullDiv.style.height=parseInt(scrollTop)+parseInt(clientHeight)+"px";
	fullDiv.style.width="100%";
	fullDiv.style.position="absolute";
	fullDiv.style.paddingTop=parseInt(scrollTop)+(parseInt(clientHeight)/2)+"px";
	fullDiv.style.top="0px";
	fullDiv.style.left="0px";
	//fullDiv.style.background="#33393C";
	fullDiv.style.zIndex=99999999;
	document.body.appendChild(fullDiv);
	document.getElementById("stop_dbclick_layer").innerHTML=
		"<table width='100%'>" +
			"<tr align='center' width='100%'>" +
			"<td align='center'>" +
				"<img src='../images/system/loading.gif' />" +
			"</td>" +
			"</tr>" +
		"</table>";
}
*/

function addCookie(url,title)
{
 if (document.all)
    {
       window.external.addFavorite(url,title);
    }
    else if (window.sidebar)
    {
       window.sidebar.addPanel(title, url, "");
 }
}

function setHomepage(url)
{
 if (document.all)
    {
        document.body.style.behavior='url(#default#homepage)';
        document.body.setHomePage(url);
 
    }
    else if (window.sidebar)
    {
    if(window.netscape)
    {
         try
   { 
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
         } 
         catch (e) 
         { 
    alert( "该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true" ); 
         }
    }
    var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
    prefs.setCharPref('browser.startup.homepage',url);
 }
}

function escapeHTML(value)
{
	if(value == null) return;
	value = value.replace(/&/g,"&amp;");
	value = value.replace(/</g, "&lt;");
	value = value.replace(/>/g, "&gt;");
	value = value.replace(/\"/g, "&quot;");
	value = value.replace(/\t/g, "    ");
	value = value.replace(/ /g, "&nbsp;");
	value = value.replace(/ /g, "&nbsp;");    //编码过的空格
    return value;
}
function unescapeHTML(value)
{
	if(value == null) return;
	value = value.replace(/&lt;/g, "<");
	value = value.replace(/&gt;/g, ">");
	value = value.replace(/&quot;/g, "\"");
	value = value.replace(/    /g, "\t");
	value = value.replace(/&nbsp;/g, " ");
	value = value.replace(/&nbsp;/g, " ");
	value = value.replace(/&amp;/g, "&");    //编码过的空格
    return value;
}

/**
 * timeStamp日期时间格式
 * @param time
 * @returns {String}
 */
function simpleDateFormat(time, format){
    var datetime = new Date();
    datetime.setTime(time);
    var year = datetime.getFullYear();
    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
    var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();
    var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
    var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
    
    return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;
}